<?php
declare (strict_types = 1);

namespace app\service;
use \app\model\AccountBookModel;

class AccountBookService extends \think\Service
{
    /**
     * 查询列表
     *
     * @return \think\Response
     */
    public function getList($data)
    {
        $query = AccountBookModel::where("is_delete",1);
        if(!empty($data['acc_id'])){
            $query->where("acc_id",$data['acc_id']);
        }
        if(!empty($data['user_id'])){
            $query->where("user_id",$data['user_id']);
        }
        $list = $query->select();
        return $list;
    }

    /**
     * 添加账本
     */
    public function create($data)
    {
        $res = AccountBookModel::create($data);
        return $res;
    }

    /**
     * 修改账本
     * @param $data
     */
    public function update($data)
    {
        $res = AccountBookModel::where('acc_id', $data['acc_id'])->update($data);
        return $res;
    }

    /**
     * 获取账本
     */
    public function getOne($data)
    {
        $query = AccountBookModel::where('acc_id', $data['acc_id'])
            ->where('is_delete', 1);
        if (!empty($data['user_id'])) {
            $query->where("user_id", $data['user_id']);
        };
        $res = $query->find();
        return $res;
    }
    /**
     * 伪删除账本
     */
    public function delete($data)
    {
        $res = AccountBookModel::where('acc_id', $data['acc_id'])->update(['is_delete'=>2]);
        return $res;
    }


}
